import { donors } from "../../database/init/donor/donorStatic";
const db=wx.cloud.database();

//获取全部捐助信息
export const getDonor = async (_openid) => {
  const res = await db.collection("donor").get();
  console.log(res.data)
  return res.data;
}

//获取捐助者信息
export const getData = async(_openid) => {
  const res=await db.collection("donor").where({
    _openid: _openid,
  }).get();
  console.log(res.data[0].students);
  return res.data[0];
}

//新增捐助者
export const addDonor = async () => {
  donors.forEach(async (donor) => {
    await db.collection("donor").add({
      data:{
        donorName:donor.donorName,
        gender:donor.gender,
        birthday:donor.birthday,
        address:donor.address,
        credit:donor.credit,
        times:donor.times,
        totalDonation:donor.totalDonation,
        students:donor.students,
        goods:donor.goods,
        projects:donor.projects
      },
      success: res => {
          console.log("add success: " + res);
      },
    });
  })
  
}